/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-03-07     Hao       the first version
 */
#ifndef PID_H
#define PID_H

class PIDController
{
public:
    /**
     * @param P - Proportional gain
     * @param I - Integral gain
     * @param D - Derivative gain
     * @param ramp - Maximum speed of change of the output value
     * @param limit - Maximum output value
     */
    PIDController(float p, float i, float d, float ramp, float limit);
    ~PIDController();

    float operator()(float error);

    float p_;           // Proportional gain
    float i_;           // Integral gain
    float d_;           // Derivative gain
    float output_ramp_; // Maximum speed of change of the output value
    float limit_;       // Maximum output value

private:
    float error_prev_;             // last tracking error value
    float output_prev_;            // last pid output value
    float integral_prev_;          // last integral component value
    unsigned long timestamp_prev_; // Last execution timestamp
};

#endif
